From 73947e5c3bc80d9241feb3d55950a8c1dbb6850f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 24 Jul 2014 19:14:18 -0700 Subject: [PATCH] Base get_fingerprint on a PackageId The fingerprinting code was erroneously using all sources from a manifest when calculating the fingerprint which meant that sources not yet downloaded were attempted to be fingerprinted. The correct source to fingerprint is located in the SourceId field of the resolved PackageId. Closes #259 --- src/cargo/core/package.rs | 18 +------- src/cargo/ops/cargo_rustc/fingerprint.rs | 12 ++++-- tests/test_cargo_compile_git_deps.rs | 55 ++++++++++++++++++++++++ tests/test_cargo_compile_path_deps.rs | 19 +------- tests/test_cargo_compile_plugins.rs | 9 +--- 5 files changed, 69 insertions(+), 44 deletions(-) diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 96175b9a1..40b59d99e 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -12,9 +12,9 @@ use core::{ Summary }; use core::dependency::SerializedDependency; -use util::{CargoResult, graph, Config}; +use util::{CargoResult, graph}; use serialize::{Encoder,Encodable}; -use core::source::{SourceId, SourceSet, Source}; +use core::source::{SourceId, Source}; // TODO: Is manifest_path a relic? #[deriving(Clone)] @@ -116,20 +116,6 @@ impl Package { ret.push_all(self.manifest.get_source_ids()); ret } - - pub fn get_fingerprint(&self, config: &mut Config) -> CargoResult { - let mut sources = self.get_source_ids(); - // Sort the sources just to make sure we have a consistent fingerprint. - sources.sort_by(|a, b| { - let a = (&a.kind, a.location.to_string()); - let b = (&b.kind, b.location.to_string()); - a.cmp(&b) - }); - let sources = sources.iter().map(|source_id| { - source_id.load(config) - }).collect::>(); - SourceSet::new(sources).fingerprint(self) - } } impl Show for Package { diff --git a/src/cargo/ops/cargo_rustc/fingerprint.rs b/src/cargo/ops/cargo_rustc/fingerprint.rs index df17c0d7f..1f6325eae 100644 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@ -5,7 +5,7 @@ use std::io::{fs, File}; use core::{Package, Target}; use util; use util::hex::short_hash; -use util::{CargoResult, Fresh, Dirty, Freshness}; +use util::{CargoResult, Fresh, Dirty, Freshness, Config}; use super::job::Job; use super::context::Context; @@ -75,8 +75,8 @@ pub fn prepare(cx: &mut Context, pkg: &Package, fn is_fresh(dep: &Package, loc: &Path, cx: &mut Context, targets: &[&Target]) -> CargoResult<(bool, String)> { - let new_pkg_fingerprint = format!("{}{}", cx.rustc_version, - try!(dep.get_fingerprint(cx.config))); + let dep_fingerprint = try!(get_fingerprint(dep, cx.config)); + let new_pkg_fingerprint = format!("{}{}", cx.rustc_version, dep_fingerprint); let new_fingerprint = fingerprint(new_pkg_fingerprint, hash_targets(targets)); @@ -103,3 +103,9 @@ fn fingerprint(package: String, profiles: u64) -> String { let hasher = SipHasher::new_with_keys(0,0); util::to_hex(hasher.hash(&(package, profiles))) } + +fn get_fingerprint(pkg: &Package, config: &mut Config) -> CargoResult { + let source_id = pkg.get_package_id().get_source_id(); + let source = source_id.load(config); + source.fingerprint(pkg) +} diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index 3a0f52b2c..a295e85bc 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -1,4 +1,5 @@ use std::io::File; +use std::path; use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths}; use support::{cargo_dir}; @@ -99,6 +100,60 @@ test!(cargo_compile_simple_git_dep { execs().with_stdout("hello world\n")); }) +test!(override_git_dep { + let p = project("foo"); + let root = p.root().clone(); + let p = p + .file(".cargo/config", format!(r#" + paths = ['{}/baz'] + "#, root.display())) + .file("Cargo.toml", r#" + [package] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [dependencies.bar] + path = "bar" + "#) + .file("src/main.rs", "extern crate bar; fn main() {}") + .file("bar/Cargo.toml", r#" + [package] + + name = "bar" + version = "0.5.0" + authors = ["wycats@example.com"] + + [dependencies.baz] + git = 'git://example.com/path/to/nowhere' + "#) + .file("bar/src/lib.rs", "extern crate baz;") + .file("baz/Cargo.toml", r#" + [package] + + name = "baz" + version = "0.5.0" + authors = ["wycats@example.com"] + "#) + .file("baz/src/lib.rs", ""); + + assert_that(p.cargo_process("cargo-build"), + execs() + .with_stdout(format!("{compiling} baz v0.5.0 (file:{dir}{sep}baz)\n\ + {compiling} bar v0.5.0 (file:{dir})\n\ + {compiling} foo v0.5.0 (file:{dir})\n", + compiling = COMPILING, dir = root.display(), + sep = path::SEP)) + .with_stderr("")); + + assert_that(&p.bin("foo"), existing_file()); + + assert_that( + cargo::util::process(p.bin("foo")), + execs().with_stdout("")); +}) + test!(cargo_compile_git_dep_branch { let project = project("foo"); let git_project = git_repo("dep1", |project| { diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index 3d73e809c..194f10e52 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -161,8 +161,7 @@ test!(cargo_compile_with_transitive_dev_deps { [dev-dependencies.baz] - version = "0.5.0" - path = "baz" + git = "git://example.com/path/to/nowhere" [[lib]] @@ -172,22 +171,6 @@ test!(cargo_compile_with_transitive_dev_deps { pub fn gimme() -> &'static str { "zoidberg" } - "#) - .file("bar/baz/Cargo.toml", r#" - [project] - - name = "baz" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[lib]] - - name = "baz" - "#) - .file("bar/baz/src/baz.rs", r#" - pub fn gimme() -> &'static str { - "nope" - } "#); assert_that(p.cargo_process("cargo-build"), diff --git a/tests/test_cargo_compile_plugins.rs b/tests/test_cargo_compile_plugins.rs index 98396c8e5..80e64088b 100644 --- a/tests/test_cargo_compile_plugins.rs +++ b/tests/test_cargo_compile_plugins.rs @@ -1,10 +1,5 @@ -use std::os; -use std::path; - -use support::{project, execs, basic_bin_manifest}; -use support::{RUNNING, COMPILING}; -use hamcrest::{assert_that, existing_file}; -use cargo::util::process; +use support::{project, execs}; +use hamcrest::assert_that; fn setup() { } -- 2.30.2